﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Collections;
using System.Configuration;

namespace MyVocationSpace
{
    public partial class ApproveIndustry : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;

            if (Session["UserID"] == null)
            {
                Response.Redirect("Home.aspx");
            }
            else if (Session["UserID"].ToString() != "")
            {
                if (Session["IsAdmin"] == null)
                {
                    Response.Redirect("Home.aspx");
                }
                else
                {
                    if (!Convert.ToBoolean(Session["IsAdmin"]))
                    {
                        Response.Redirect("Home.aspx");
                    }
                }
            }

            if (!IsPostBack)
            {
                PopulateIndustry();
            }
        }


        public void PopulateIndustry()
        {
            DataSet ds = BAL.Industry.GetAllTempIndustry();
            if (ds != null)
            {
                gdApproveIndustry.DataSource = ds;
                gdApproveIndustry.DataBind();
            }
        }

        protected void gdApproveIndustry_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gdApproveIndustry.PageIndex = e.NewPageIndex;
            PopulateIndustry();
        }
        //protected void lnkName_Click(object sender, EventArgs e)
        //{
        //    LinkButton lnkNm = (LinkButton)sender;
        //    GridViewRow gdrw = (GridViewRow)lnkNm.Parent.Parent;
        //    int rowIndex = Convert.ToInt32(lnkNm.CommandArgument);
        //    //lblId.Text = gvrow.RowIndex.ToString();

        //    int IDUser = Convert.ToInt32(gdApproveIndustry.DataKeys[rowIndex]["IDUser"]);
        //    string[] detail = BAL.Vocation.SelectUserDetails(IDUser);

        //    lblName.Text = detail[0];
        //    lblEmail.Text = detail[3];
        //    lblIndustryName.Text = detail[4];
        //    lblDescription.Text = detail[5];

        //}
        protected void btnapprv_Click(object sender, EventArgs e)
        {
            Hashtable hstData = new Hashtable();
            List<String> name = new List<String>();

            foreach (GridViewRow dr in gdApproveIndustry.Rows)
            {
                CheckBox chkapp = (CheckBox)dr.Cells[5].FindControl("chkApprove");

                // bool isChecked = ((CheckBox)dr.FindControl("chkApprove")).Checked;

                if (chkapp != null && chkapp.Checked)
                {
                    //   _emailid.Add(dr.Cells[0].Text );
                    name.Add(dr.Cells[1].Text);
                    hstData.Add(gdApproveIndustry.DataKeys[dr.RowIndex]["IDTempIndustry"], dr.Cells[1].Text);

                }
            }

            if (hstData.Count > 0)
            {
                for (int i = 0; i < hstData.Count; i++)
                {
                    // string strContent = "hi";
                    // foreach(String keys in _emailid)
                    foreach (int key in hstData.Keys)
                    {

                        //BAL.Industry.ApproveTempIndustry(key);
                        string content = "<div style=\"margin-left:20px;\">" +
                            "<span style=\"font-size: 12px; font-family: 'CENTURY GOTHIC'\">" +
                            "<br>Dear <b>" + name[i] + "</b>,<br><br>" +
                            "We are pleased to welcome you to the <b>" + ConfigurationManager.AppSettings["SiteName"].ToString() + "</b> !<br><br>" +
                            "Administrator has Approved your Industry." +

                      "<br><br>Best Regards, <br>" + ConfigurationManager.AppSettings["SiteName"].ToString() + " Team<br><a href='http://www.myvocationspace.com'>www." + ConfigurationManager.AppSettings["SiteName"].ToString() + ".com</a></span><br><br><img src='cid:companylogo' style='width:200px;hight:150px'>" +
               "<br><p>Follow Us on </p><div class='addthis_toolbox addthis_32x32_style addthis_default_style'>" +
"<a class='addthis_button_facebook_follow' addthis:userid=''></a>" +
"<a class='addthis_button_twitter_follow' addthis:userid='romstermonster'></a></div>" +
"<script type='text/javascript' src='http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4fa12a956ba9df5c'></script>" +
           "<div style=\"float:left;margin:0px 5px 0px 5px\" ><a href='' target='_blank'><img src='cid:fb' style='border:0' /></a></div>" +
           "<div style=\"float:left;margin:0px 5px 0px 5px\" ><a href='' target='_blank'><img src='cid:tweet' style='border:0' /></a></div>";

                        string subject = "Approved Industry";

                        BAL.Common.SendEmail("", hstData[key].ToString(), subject, content);
                    }
                }

            } 
        }


        protected void lnkIDTempIndustry_Click(object sender, EventArgs e)
        {
            LinkButton lnkNm = (LinkButton)sender;
            GridViewRow gdrw = (GridViewRow)lnkNm.Parent.Parent;
            int rowIndex = Convert.ToInt32(lnkNm.CommandArgument);
            //lblId.Text = gvrow.RowIndex.ToString();

            //int IDUser = Convert.ToInt32(gdApproveIndustry.DataKeys[rowIndex]["IDUser"]);
            string[] detail = BAL.Vocation.GetUserTempIndustryDetails(rowIndex);


            lblFName.Text = detail[0];
            lblLName.Text = detail[1];
            lblEmail.Text = detail[3];
            lblIndustryName.Text = detail[4];
            lblDescription.Text = detail[5];
            lblIDTempIndustry.Text = detail[6];
            AI_ModalPopupExtender.Show();
        }

        protected void btnAppoveIndustry_Click(object sender, EventArgs e)
        {
            int IDTempInd = Convert.ToInt32(lblIDTempIndustry.Text);
            string reason = txtAppoveDisApp.Text;
            bool status = false;
            if (rdIndustry.SelectedValue == "1")
            {
                status = true;
            }

            BAL.Industry.ApproveTempIndustry(status, reason, IDTempInd);      

            PopulateIndustry();

            string content = "<div style=\"margin-left:20px;\">" +
                            "<span style=\"font-size: 12px; font-family: 'CENTURY GOTHIC'\">" +
                            "<br>Dear <b>" + lblFName.Text + "</b>,<br><br>" +
                            "We are pleased to welcome you to the <b>" + ConfigurationManager.AppSettings["SiteName"].ToString() + "</b> !<br><br>" +
                            "Administrator has Approved your Industry.<br>" +
                            "<br><b>Industry Name</b> " + lblIndustryName.Text + "<br>" +
                             "<br><b>Description</b> " + reason + "<br>" +
                      "<br><br>Best Regards, <br>" + ConfigurationManager.AppSettings["SiteName"].ToString() + " Team<br><a href='http://www.myvocationspace.com'>www." + ConfigurationManager.AppSettings["SiteName"].ToString() + ".com</a></span><br><br><img src='cid:companylogo' style='width:200px;hight:150px'>" +
               "<br><p>Follow Us on </p><div class='addthis_toolbox addthis_32x32_style addthis_default_style'>" +
"<a class='addthis_button_facebook_follow' addthis:userid=''></a>" +
"<a class='addthis_button_twitter_follow' addthis:userid='romstermonster'></a></div>" +
"<script type='text/javascript' src='http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4fa12a956ba9df5c'></script>" +
           "<div style=\"float:left;margin:0px 5px 0px 5px\" ><a href='' target='_blank'><img src='cid:fb' style='border:0' /></a></div>" +
           "<div style=\"float:left;margin:0px 5px 0px 5px\" ><a href='' target='_blank'><img src='cid:tweet' style='border:0' /></a></div>";

            string subject = "Approved Industry from website www.myvocationspace.com";

            BAL.Common.SendEmail("", lblEmail.Text, subject, content);

            idspanApprove.Style.Add("display", "block");
            idspanApprove.InnerHtml = "Your status successfully submitted.";
            
        }

        protected void gdApproveIndustry_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbl = (Label)e.Row.FindControl("lblApprove");
                bool isApprove = Convert.ToBoolean(lbl.Text);
                if (isApprove)
                {
                    lbl.Text = "Approve";
                }
                else
                {
                    lbl.Text = "Disapprove";
                }
            }
        }

    }
}